<route lang="json5" type="page">
{
  style: {
    navigationBarTitleText: '合作入驻',
  },
}
</route>

<template>
  <div class="join-in">
    <div class="item active" @click="toPage('apply-for')">
      <div class="icon">
        <image src="./images/ysj.png" />
      </div>
      <div class="info">
        <div class="title">艺术家入驻</div>
        <div class="tip">免费入住和推广</div>
      </div>
    </div>
    <div class="item active" @click="toPage('promotion')">
      <div class="icon">
        <image src="./images/tgds.png" />
      </div>
      <div class="info">
        <div class="title">推广大使</div>
        <div class="tip">帮卖赚佣金</div>
      </div>
    </div>
    <div class="item active" @click="toPage('hotel')">
      <div class="icon">
        <image src="./images/msxz.png" />
      </div>
      <div class="info">
        <div class="title">民宿入驻</div>
        <div class="tip">我要接单</div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { msgNone, msgSuccess, showModal } from '@/utils/index'
import { to } from '@/utils/page'
import { useUserStore } from '@/store/user'

const userStore = useUserStore()

function toPage(path) {
  if (userStore.isLogged) {
    getStatus(path)
  } else {
    userStore.setShowModal(true)
  }
}

function getStatus(path) {
  const mode = {
    'apply-for': {
      path: '/artist-authorized-app/open/detail',
      filter: { id: userStore.userInfo.userId },
    },
    promotion: {
      path: '/general-members-app/detail',
      filter: { userId: userStore.userInfo.userId },
    },
    hotel: {
      path: '/hotels-info-app/open/detail',
      filter: { id: userStore.userInfo.userId },
    },
  }

  if (path === 'hotel') {
    to(`/pages-sub/join-in/${path}`)
    return
  }

  uni.showLoading()
  http
    .get(mode[path].path, mode[path].filter)
    .then((res: any) => {
      if (res) {
        if (path === 'hotel') {
          res = res.qualification // 酒店信息在二级
        }

        if (res.status === 0) {
          msgNone('当前正在审核中，请耐心等待')
        }
        if (res.status === 1) {
          msgSuccess('您的审核已通过')
        }
        if (res.status === 2) {
          showModal({
            title: '您的审核未通过',
            content: res.auditRemark,
            showCancel: true,
            confirmText: '重新提交',
          }).then(() => {
            to(`/pages-sub/join-in/${path}`)
          })
        }
      } else {
        to(`/pages-sub/join-in/${path}`)
      }
    })
    .finally(() => {
      uni.hideLoading()
    })
}
</script>

<style lang="scss" scoped>
.join-in {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background-color: #f1f1f1;

  .item {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    width: 504rpx;
    height: 288rpx;
    padding-left: 80rpx;
    margin-bottom: 60rpx;
    background: #ffffff;
    border-radius: 38rpx;
    box-shadow: 0px 16.35px 49.04px #e9eff5;
    .icon {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 123rpx;
      height: 123rpx;
      margin-right: 20rpx;
      background: linear-gradient(134.53deg, rgba(113, 113, 117, 1) 0%, rgba(31, 32, 38, 1) 100%);
      border-radius: 48rpx;
      box-shadow: 0px 17rpx 28rpx rgba(31, 32, 38, 0.3);
      image {
        width: 80rpx;
        height: 80rpx;
      }
    }

    .title {
      font-size: 38rpx;
      font-weight: 500;
      color: var(--color1);
    }
    .tip {
      margin-top: 8rpx;
      font-size: 27rpx;
      color: var(--color4);
    }
  }
}
</style>
